﻿using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Dsl.Ped.Common.Helpers;
using Dsl.Ped.Framework.AddIns;

namespace Dsl.Ped.Desktop.Helpers
{
    /// <summary>
    /// Helper of the <see cref="IDslPedAddInMetadata"/>
    /// </summary>
    public class AddInMetadataHelper
    {
        /// <summary>
        /// Get the image representing the add-in from the <see cref="addInMetadata"/>
        /// </summary>
        /// <param name="addInMetadata">Metadata of an add-in</param>
        /// <returns><see cref="ImageSource"/> representing the add-in</returns>
        public static ImageSource GetAddInImageSource(IDslPedAddInMetadata addInMetadata)
        {
            var largeImage = UriHelper.GetAssemblyResource(TypeHelper.GetAssembly(addInMetadata.ProjectiveType), addInMetadata.ImageUri);
            try
            {
                var largeImageSource = new BitmapImage(largeImage);
                return largeImageSource;
            }
            catch (Exception exc)
            {
                return ImageSourceHelper.GetDefaultImageSource("Resources/Images/plug.png", "DSLPedDesktop");
            }
        }
    }
}
